import 'package:flutter/material.dart';
import 'package:pwd_keeper/global.dart';
import 'package:pwd_keeper/iconfont.dart';
import 'icon_picker.dart';

class IconPickerBuilder extends StatelessWidget {
  final String iconData;
  final ValueChanged<String> action;

  IconPickerBuilder({
    @required this.iconData,
    @required this.action,
  });

  @override
  Widget build(BuildContext context) {
    return InkWell(
      borderRadius: BorderRadius.circular(5),
      onTap: () {
        showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text(
                '选择账号图标',
                style: TextStyle(
                  color: Global.fontColor,
                  fontSize: 16,
                ),
              ),
              content: SingleChildScrollView(
                child: IconPicker(
                  currentIconData: iconData,
                  onIconChanged: action,
                ),
              ),
            );
          },
        );
      },
      child: Center(
        child: Container(
          width: 100,
          height: 120,
          child: Stack(
            children: [
              Positioned(
                top: 10,
                left: 0,
                child: Image.asset('assets/images/$iconData.png', width: 100),
              ),
              Positioned(
                top: 3,
                right: 0,
                child: Icon(
                  IconFont.edit,
                  color: Global.fontSecondColor,
                  size: 20,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
